// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import http from './utils/http';
import constant from './utils/constant';
import axios from 'axios';
let Config = process.env;
import 'element-ui/lib/theme-chalk/index.css';
import Element, {
  Dialog,
  Loading,
  Message
} from 'element-ui';
import './assets/css/base.css';
import utils from './utils/util.js';
Vue.prototype.utils = utils;
Vue.use(Dialog);
Vue.use(Element);
Vue.prototype.$msg = Message;


Vue.prototype.$post = http.post;
Vue.prototype.$get = http.get;
Vue.prototype.$constant = constant;

Vue.filter('filterSupplierType', function (value) {
  var typeArr = [{
    type: 'INVESTOR',
    name: '投资人'
  }, {
    type: 'RESTAURANT',
    name: '餐厅'
  }, {
    type: 'SUPPLIER',
    name: '供应商'
  }];
  for (var i in typeArr) {
    if (typeArr[i].type == value) {
      return typeArr[i].name;
    }
  }
});
Vue.filter('filterStockUseType', function (value) {
  var typeArr = [{
    type: 'SALES',
    name: '销货单'
  }, {
    type: 'SALES_RETURN',
    name: '销货退货单'
  }, {
    type: 'REQUISITION',
    name: '调拨单'
  }, {
    type: 'INSINGLE',
    name: '集采单'
  }, {
    type: 'REPURCHASE',
    name: '回购单'
  }];
  for (var i in typeArr) {
    if (typeArr[i].type == value) {
      return typeArr[i].name;
    }
  }
})
Vue.filter('formatDate', function (value) { //时间戳转换
  if (!value) {
    return "";
  }
  var time = new Date(Number(value) * 1000);
  var Y = time.getFullYear();
  var m = time.getMonth() + 1;
  var d = time.getDate();
  var H = time.getHours();
  var mi = time.getMinutes();
  var s = time.getSeconds();
  if (m < 10) {
    m = '0' + m;
  }
  if (d < 10) {
    d = '0' + d;
  }
  if (H < 10) {
    H = "0" + H;
  }
  if (mi < 10) {
    mi = '0' + mi;
  }
  if (s < 10) {
    s = "0" + s;
  }
  return (Y + "-" + m + "-" + d + " " + H + ":" + mi + ":" + s);
});
//=======网络监听====== 
axios.interceptors.request.use(
  config => {
    if (Config.NODE_ENV === "development") {
      // console.group("--------axios-------")
      // console.log("---url---\n",config.url)
      // console.log("---data---\n",config.data)
      // console.log("---headers---\n",config.headers)
      // console.groupEnd("--------axios-------")
    }
    //TODO 处理token信息
    return config;
  },
  error => {
    //TODO 处理token过期消息或者统一错误处理
    return Promise.reject(error.data.error.message);
  }
);
router.afterEach((to, fromx, m) => {
  //自动修改标题，在路由配置meta
  document.title = to.meta.title;
  if (Config.NODE_ENV === "development") {
    console.group("--------router--------")
    console.log(fromx);
    console.log(to);
    console.groupEnd();
  }
})

Vue.config.productionTip = false

Vue.prototype.$loading = Loading.service;
new Vue({
  el: '#app',
  router,
  components: {
    App
  },
  template: '<App/>'
})
